<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AdverModel
 *
 * @author yaoyunhua
 */
namespace Admin\Model;
use Think\Model\RelationModel;
class AdverModel  extends RelationModel {
    //put your code here
    protected  $tableName = 'adver';
    protected $_auto = array (
        array('add_time','time',2,'function'), // 对add_time字段在tj添加"时候写入当前时间戳
    );
    protected $_link = array(
        'Adv'=>array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'  => 'adver_place',
            'mapping_name' => 'adverplaces',
            'foreign_key' =>  'prid',
            'parent_key'  => 'id'
        ),
    );
    //获取广告列表
    public function getAdvList($where=[],$page=false){
        $data = array();
        if ($page) {
            $data['count'] = $this->where($where)->count();
            $p = getPage($data['count'],15);
            $data['list'] =  $this->relation(true)->where($where)->limit($p->firstRow,$p->listRows)->order('position')->select();
            $data['pageInfo'] =  $p;
        }else{
            $data['list'] =  $this->relation(true)->where($where)->order('position')->select();
        }
        return $data;
    }
    //删除广告
    public function delAdv($advId){

        return $this->where("id = ".$advId)->delete();
    }
    //编辑广告
    public function getAdvInfoById($advId){
        return $this->where("id = ".$advId)->find();
    }
    
}